// UIThread.cpp : implementation file
//

#include "stdafx.h"
#include "UIThread.h"

#define UM_UIWORK		(WM_USER+1)


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CUIThread

IMPLEMENT_DYNCREATE(CUIThread, CWinThread)

CUIThread::CUIThread()
:m_pThreadEvent(NULL),
m_lpParam(0)
{
}

CUIThread::~CUIThread()
{
}

BOOL CUIThread::InitInstance()
{
	// TODO:  perform and per-thread initialization here
	return TRUE;
}

int CUIThread::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CUIThread, CWinThread)
	//{{AFX_MSG_MAP(CUIThread)
	ON_THREAD_MESSAGE(UM_UIWORK, OnUIWork)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUIThread message handlers

void CUIThread::OnUIWork(UINT wParam, LONG lParam)
{
	if(m_pThreadEvent)
		m_pThreadEvent(m_lpParam);

	AfxEndThread(0);
}


BOOL CUIThread::StartThread(ThreadEvent* pThreadEvent, LPVOID lpParam)
{
	CUIThread* p = (CUIThread *)AfxBeginThread(RUNTIME_CLASS(CUIThread));
	p->m_pThreadEvent = pThreadEvent;
	p->m_lpParam = lpParam;
	p->PostThreadMessage(UM_UIWORK, 0, 0);
	return TRUE;
}


